$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'quotePrint/quoteprint/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '印刷机名称', name: 'printName', index: 'print_name', width: 80 }, 			
			{ label: '机器类型', name: 'printType', index: 'print_type', width: 80,
				formatter:function(value){
                    if(value == 'one_kai'){
                        return '全开'
                    }else if (value == 'two_kai'){
                        return '对开'
					}else if (value == 'four_kai'){
                        return '四开'
                    }else if(value == 'eight_kai'){
                        return '八开'
                    }
				}
			},
			{ label: 'type', name: 'machineType', index: 'machine_type', width: 80,
                formatter:function(value){
                    if(value == 'putong'){
                        return '普通'
                    }else if (value == 'shangwuyinshua'){
                        return '商务印刷'
                    }else if (value == 'shumakuaiyin'){
                        return '数码快印'
                    }else if(value == 'guanggaowuliao'){
                        return '广告物料'
                    }
                }},
			{ label: '最小尺寸(长)', name: 'printMinLength', index: 'print_min_length', width: 80 }, 			
			{ label: '最小尺寸(宽)', name: 'printMinWide', index: 'print_min_wide', width: 80 }, 			
			{ label: '最大尺寸(长)', name: 'printMaxLength', index: 'print_max_length', width: 80 }, 			
			{ label: '最大尺寸(宽)', name: 'printMaxWide', index: 'print_max_wide', width: 80 }, 			
			{ label: '排序', name: 'printSort', index: 'print_sort', width: 80 }, 			
			{ label: '是否删除', name: 'delFlag', index: 'del_flag', width: 80,
                formatter:function(value){
                    if(value == 0){
                        return '不删除'
                    }else if (value == 1){
                        return '已删除'
                    }else{
                    	return 'error';
					}
                }},
			{ label: '创建时间', name: 'createDate', index: 'create_date', width: 80 },
			{ label: '更新时间', name: 'updateDate', index: 'update_date', width: 80 }, 			
			{ label: '创建人员', name: 'createUser', index: 'create_user', width: 80 }, 			
			{ label: '更新人员', name: 'updateUser', index: 'update_user', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		quotePrint: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.quotePrint = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.quotePrint.id == null ? "quotePrint/quoteprint/save" : "quotePrint/quoteprint/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.quotePrint),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "quotePrint/quoteprint/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "quotePrint/quoteprint/info/"+id, function(r){
                vm.quotePrint = r.quotePrint;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});